package de.sendorian.app.forumArchive.script;

import java.util.LinkedHashSet;
import java.util.Set;

import org.joda.time.DateTime;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import de.sendorian.app.forumArchive.Compressor;
import de.sendorian.app.forumArchive.Config;
import de.sendorian.app.forumArchive.repository.ForumRepository;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/application-context.xml")
@Ignore
public class ActionScripts {

    @Autowired
    ForumRepository forumRepository;

    @Autowired
    Compressor compressor;

    @Autowired
    Config config;


    @Test
    public void compressImagesInFolders() {
        String downloadDir = config.getDownloadDir();
        Set<String> folders = new LinkedHashSet<String>();
        folders.add(downloadDir + "/Objects and Textures (Fantasy)/For hes a lumberjack");
        compressor.compressImagesInFolders(folders);
    }


    @Test
    public void compressImagesInTopicsByDate() {
        doCompressImagesInTopicsByDate(2009, 10, 1);
    }


    @Test
    public void compressAllImagesInTopics() {
        doCompressImagesInTopicsByDate(2000, 1, 1);
    }


    private void doCompressImagesInTopicsByDate(int year, int month, int day) {
        DateTime start = new DateTime().withDate(year, month, day);
        compressor.compressImages(forumRepository.findAll());
        forumRepository.shutdownDatabase();
    }

}
